<?php
/**
 * Created by PhpStorm.
 * User: gqn
 * Date: 16/5/25
 * Time: 下午9:37
 */
namespace Admin\Controller;
class CommentController extends CommonController{

	protected $HANDLE_START_MASTER= 10;
	protected $HANDLE_START_USER= 3;

	protected function _initialize(){
		parent::_initialize();
	}

	/**
	 * 已评价 师傅/业主
	 */

	public function Complete(){
		$role = I('get.role');
		$user = I('get.user');
		$master = I('get.master');
		$start_time = I('get.start_time','');
		$end_time = I('get.end_time','');
		$order_id = I('get.order_id');
		$menu_id=$_GET['id'];
		$jur=jur_str($menu_id,$this->user_id);
		if($start_time!=''){
			$start_time = strtotime($start_time);
		}
		if($end_time!=''){
			$end_time = strtotime($end_time);
		}
		if($user) {
			$map['usr.user_name'] = array('like',"%$user%");
		}
		if($master){
			$map['info.id_name'] = array('like',"%$master%");
		}
		if($order_id){
			$map['com.order_id'] = array('like',"%$order_id%");
		}
		if($start_time && $end_time){
			$map['com.add_time'] = array('between',$start_time.','.$end_time);
		}elseif($start_time){
			$map['com.add_time'] = array('egt',$start_time);
		}

		if($role=='master'){
			$count = M()->table('zsf_comment_master com')->DISTINCT(true)
				->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
				->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
				->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
				->join('zsf_user_real_info info on info.user_id = com.worker_user_id')
				->where($map)->count();
			$Page  = new \Think\Page($count,10);// 实例化
			$show  = $Page->show();// 分页显示输出

			$data = M()->table('zsf_comment_master com')->DISTINCT(true)
				    ->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
					->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
					->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
					->join('zsf_user_real_info info on info.user_id = com.worker_user_id')
					->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();

			if($data) {
				foreach ($data as $k => $v) {
					$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
					$data[$k]['star'] = $data[$k]['speed'] + $data[$k]['attitude'] + $data[$k]['skill'] + $data[$k]['health'] + $data[$k]['charge'];
				}
			}
			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='已评价-对师傅';
			$this->assign('complete',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display();


		}elseif($role=='user'){
			$count = M()->table('zsf_comment_user com')->DISTINCT(true)
				->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
				->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
				->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
				->join('LEFT JOIN zsf_user as wok on wok.user_id = com.worker_user_id')
				->join('LEFT JOIN zsf_user_real_info info on info.user_id = com.worker_user_id')
				->where($map)->count();
			$Page  = new \Think\Page($count,10);// 实例化
			$show  = $Page->show();// 分页显示输出

			$data = M()->table('zsf_comment_user com')->DISTINCT(true)
				->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
				->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
				->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
				->join('LEFT JOIN zsf_user as wok on wok.user_id = com.worker_user_id')
				->join('LEFT JOIN zsf_user_real_info info on info.user_id = com.worker_user_id')
				->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();

			foreach ($data as $k => $v) {
				$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
				$fault_id = $data[$k][fault_id_list];
				if($fault_id) {
					$info = M('fault')->field('name')->where("fault_id in ($fault_id)")->select();
					$info = array_column($info, 'name');
					$data[$k]['fault_name'] = implode(',', $info);
				}
				if ($data[$k]['fault_type'] == '1') {
					$data[$k]['fault_type'] = '标准';
				} else {
					$data[$k]['fault_type'] = '非标准';
				}
			}

			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='评价-对用户';
			$this->assign('complete',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display('Comment');
		}
	}

	/**
	 * 待评价
	 */
	public function Wait(){
		$role=I('get.role');
		$user = I('get.user');
		$master = I('get.master');
		$start_time = I('get.start_time','');
		$end_time = I('get.end_time','');
		$order_id = I('get.order_id');
		$menu_id=$_GET['id'];
		$jur=jur_str($menu_id,$this->user_id);

		if($start_time!=''){
			$start_time = strtotime($start_time);
		}
		if($end_time!=''){
			$end_time = strtotime($end_time);
		}
		if($user) {
			$map['usr.user_name'] = array('like',"%$user%");
		}
		if($master){
			$map['info.id_name'] = array('like',"%$master%");
		}
		if($start_time && $end_time){
			$map['rep.pay_time'] = array('between',$start_time.','.$end_time);
		}elseif($start_time){
			$map['rep.pay_time'] = array('egt',$start_time);
		}

		if($role=='master'){
				if($order_id){
					$map['rep.repair_order_num_alias'] = array('like',"%$order_id%");
				}

				$map['rep.status'] = array('eq',8);
				$map['rep.master_comment'] = array('eq',0);


				$count = M()->table('zsf_repair_order rep')
				->field('rep.repair_order_num_alias,rep.category_name,rep.fault_id_list,rep.fault_type,rep.pay_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
				->join('LEFT JOIN zsf_user as usr on usr.user_id = rep.user_id')
				->join('LEFT JOIN zsf_user as wok on wok.user_id = rep.worker_user_id')
				->join('LEFT JOIN zsf_user_real_info as info on rep.worker_user_id = info.user_id')
				->where($map)->count();

				$Page  = new \Think\Page($count,10);// 实例化
				$show  = $Page->show();// 分页显示输出

				$data = M()->table('zsf_repair_order rep')
						->field('rep.repair_order_num_alias,rep.category_name,rep.fault_id_list,rep.fault_type,rep.pay_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
						->join('LEFT JOIN zsf_user as usr on usr.user_id = rep.user_id')
						->join('LEFT JOIN zsf_user as wok on wok.user_id = rep.worker_user_id')
						->join('LEFT JOIN zsf_user_real_info as info on rep.worker_user_id = info.user_id')
						->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();

					foreach ($data as $k => $v) {
						$data[$k]['pay_time'] = date('Y-m-d H:i:s', $data[$k]['pay_time']);
						$fault_id = $data[$k][fault_id_list];
						$info = M('fault')->field('name')->where("fault_id in ($fault_id)")->select();
						$info = array_column($info, 'name');
						$data[$k]['fault_name'] = implode(',', $info);
						if ($data[$k]['fault_type'] == '1') {
							$data[$k]['fault_type'] = '标准';
						} else {
							$data[$k]['fault_type'] = '非标准';
						}
					}

			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='待评价-对师傅';
			$this->assign('Wait',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display();
		}
	}


	/**
	 * 预警评价
	 */

	public function Warning(){
		$role = I('get.role');
		$user = I('get.user');
		$master = I('get.master');
		$start_time = I('get.start_time','');
		$end_time = I('get.end_time','');
		$order_id = I('get.order_id');
		$menu_id=$_GET['id'];
		$jur=jur_str($menu_id,$this->user_id);

		if($start_time!=''){
			$start_time = strtotime($start_time);
		}
		if($end_time!=''){
			$end_time = strtotime($end_time);
		}
		if($user){
			$map['usr.user_name'] = array('like',"%$user%");
		}
		if($master){
			$map['info.id_name'] = array('like',"%$master%");
		}
		if($order_id){
			$map['com.order_id'] = array('like',"%$order_id%");
		}
		if($start_time && $end_time){
			$map['com.add_time'] = array('between',$start_time.','.$end_time);
		}elseif($start_time){
			$map['com.add_time'] = array('egt',$start_time);
		}

		if($role=='master'){
			$count = M()->table('zsf_comment_master com')->DISTINCT(true)
					->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
					->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
					->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
					->join('zsf_user_real_info info on info.user_id = com.worker_user_id')
					->where($map)->count();
			$Page  = new \Think\Page($count,10);// 实例化
			$show  = $Page->show();// 分页显示输出

			$data = M()->table('zsf_comment_master com')->DISTINCT(true)
				    ->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
				    ->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
					->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
					->join('zsf_user_real_info info on info.user_id = com.worker_user_id')
					->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();

			if($data) {
				foreach ($data as $k => $v) {
					$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
					$data[$k]['star'] = $data[$k]['speed'] + $data[$k]['attitude'] + $data[$k]['skill'] + $data[$k]['health'] + $data[$k]['charge'];
					if ($data[$k]['star'] > $this->HANDLE_START_MASTER) {
						unset($data[$k]);
					}
				}
			}
			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='预警评价-对师傅';
			$this->assign('Warning',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display();

		}elseif($role=='user'){
			$count = M()->table('zsf_comment_user com')->DISTINCT(true)
				->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
				->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
				->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
				->join('zsf_user as wok on wok.user_id = rep.worker_user_id')
				->join('LEFT JOIN zsf_user_real_info info on info.user_id = rep.worker_user_id')->where($map)->count();
			$Page  = new \Think\Page($count,10);// 实例化
			$show  = $Page->show();// 分页显示输出

			$data = M()->table('zsf_comment_user com')->DISTINCT(true)
					->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
					->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
					->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
					->join('zsf_user as wok on wok.user_id = rep.worker_user_id')
					->join('LEFT JOIN zsf_user_real_info info on info.user_id = rep.worker_user_id')->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();

			foreach ($data as $k => $v) {
				$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
				$fault_id = $data[$k][fault_id_list];
				$info = M('fault')->field('name')->where("fault_id in ($fault_id)")->select();
				$info = array_column($info, 'name');
				$data[$k]['fault_name'] = implode(',', $info);
				if ($data[$k]['fault_type'] == '1') {
					$data[$k]['fault_type'] = '标准';
				} else {
					$data[$k]['fault_type'] = '非标准';
				}
				if($data[$k]['point']> $this->HANDLE_START_USER){
					unset($data[$k]);
				}
			}
			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='预警评价-对用户';
			$this->assign('Warning',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display('Warning_user');
		}

	}

	/**
	 * 已处理预警评价
	 */

	public function Handled(){
		$role = I('get.role');
		$user = I('get.user');
		$master = I('get.master');
		$start_time = I('get.start_time','');
		$end_time = I('get.end_time','');
		$order_id = I('get.order_id');
		$menu_id=$_GET['id'];
		$jur=jur_str($menu_id,$this->user_id);

		if($start_time!=''){
			$start_time = strtotime($start_time);
		}
		if($end_time!=''){
			$end_time = strtotime($end_time);
		}
		if($user){
			$map['usr.user_name'] = array('like',"%$user%");
		}
		if($master){
			$map['info.id_name'] = array('like',"%$master%");
		}
		if($start_time && $end_time){
			$map['com.add_time'] = array('between',$start_time.','.$end_time);
		}elseif($start_time){
			$map['com.add_time'] = array('egt',$start_time);
		}
		if($role=='master'){
			$end = M('user_advise_visit')->field('advise_id')->where('status = 3 and role = 2')->select();
			if($end) {
				$end_id = array_column($end, 'advise_id');
				$end_order_id = implode(',', $end_id);
				if($order_id){
					$map['com.order_id'] = array(array('like',"%$order_id%"),array('in',$end_order_id));
				}else{
					$map['com.order_id'] = array('in',$end_order_id);
				}

				$count = $data = M()->table('zsf_comment_master com')->DISTINCT(true)
					->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
					->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
					->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
					->join('zsf_user_real_info info on info.user_id = com.worker_user_id')->where($map)->count();
				$Page  = new \Think\Page($count,10);// 实例化
				$show  = $Page->show();// 分页显示输出

				$data = M()->table('zsf_comment_master com')->DISTINCT(true)
						->field('com.order_id,com.skill,com.content,com.speed,com.attitude,com.health,com.charge,com.append_content,com.add_time,usr.phone as user_phone,usr.user_name,info.id_name,wok.phone as worker_phone')
						->join('LEFT JOIN zsf_user usr on com.user_id = usr.user_id')
						->join('LEFT JOIN zsf_user as wok on com.worker_user_id = wok.user_id')
						->join('zsf_user_real_info info on info.user_id = com.worker_user_id')->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();

				foreach ($data as $k => $v) {
					$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
					$data[$k]['star'] = $data[$k]['speed'] + $data[$k]['attitude'] + $data[$k]['skill'] + $data[$k]['health'] + $data[$k]['charge'];
					if ($data[$k]['star'] > 10) {
						unset($data[$k]);
					}
				}
			}
			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='已处理预警评价-对师傅';
			$this->assign('Warning',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display();

		}elseif($role=='user'){
			$end = M('user_advise_visit')->field('advise_id')->where('status=3 and role = 1')->select();

			if($end){
				$end_id = array_column($end, 'advise_id');
				$end_order_id = implode(',', $end_id);

				if($order_id){
					$map['com.order_id'] = array(array('like',"%$order_id%"),array('in',$end_order_id));
				}else{
					$map['com.order_id'] = array('in',$end_order_id);
				}
				$count = M()->table('zsf_comment_user com')->DISTINCT(true)
					->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
					->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
					->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
					->join('zsf_user as wok on wok.user_id = rep.worker_user_id')
					->join('LEFT JOIN zsf_user_real_info info on info.user_id = rep.worker_user_id')->where($map)->count();
				$Page  = new \Think\Page($count,10);// 实例化
				$show  = $Page->show();// 分页显示输出

				$data = M()->table('zsf_comment_user com')->DISTINCT(true)
						->field('com.order_id,com.point,com.content,com.add_time,rep.category_name,rep.fault_id_list,usr.user_name,usr.phone as user_phone,info.id_name,wok.phone as worker_phone')
						->join('LEFT JOIN zsf_repair_order rep on com.order_id = rep.repair_order_num_alias')
						->join('LEFT JOIN zsf_user as usr on com.user_id = usr.user_id')
						->join('zsf_user as wok on wok.user_id = rep.worker_user_id')
						->join('LEFT JOIN zsf_user_real_info info on info.user_id = rep.worker_user_id')->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();

				foreach ($data as $k => $v) {
					$data[$k]['add_time'] = date('Y-m-d H:i:s', $data[$k]['add_time']);
					$fault_id = $data[$k][fault_id_list];
					$info = M('fault')->field('name')->where("fault_id in ($fault_id)")->select();
					$info = array_column($info, 'name');
					$data[$k]['fault_name'] = implode(',', $info);
					if ($data[$k]['fault_type'] == '1') {
						$data[$k]['fault_type'] = '标准';
					} else {
						$data[$k]['fault_type'] = '非标准';
					}
				}
			}
			$this->breadcrumb1='评价管理';
			$this->breadcrumb2='已处理预警评价-对用户';
			$this->assign('Warning',$data);
			$this->assign('page',$show);
			$this->assign('update',$jur['is_update']);// 赋值数据集
			$this->assign('delete',$jur['is_delete']);// 赋值数据集
			$this->display('Handled_user');
		}
	}

	/**
	 * 回访记录
	 */

	public function Visit(){
		$advise_id = I('get.advise_id');
		$advise_id_user = I('get.advise_id_user','');

		if(empty($advise_id_user)) {
			$info = M('user_advise_visit')->where("advise_id = $advise_id and status = 3 and role = 2")->select();
			if ($info) {
				foreach ($info as $k => $v) {
					$info[$k]['add_time'] = date('Y-m-d H:i:s', $info[$k]['add_time']);
					if ($info[$k]['result'] == '1') {
						$info[$k]['result'] = '继续回访';
					} else {
						$info[$k]['result'] = '处理完毕';
					}
				}
			} else {
				$info[0]['advise_id'] = $advise_id;
			}
			$this->breadcrumb1 = '评价管理';
			$this->breadcrumb2 = '预警评价-对师傅';
			$this->breadcrumb3 = '回访记录';
			$this->url2 = U('Comment/Warning') . '&role=master';
			$this->assign('advise', $info);
			$this->display();

		}else{
			$info = M('user_advise_visit')->where("advise_id = $advise_id_user and status = 3 and role = 1")->select();
			if ($info) {
				foreach ($info as $k => $v) {
					$info[$k]['add_time'] = date('Y-m-d H:i:s', $info[$k]['add_time']);
					if ($info[$k]['result'] == '1') {
						$info[$k]['result'] = '继续回访';
					} else {
						$info[$k]['result'] = '处理完毕';
					}
				}
			} else {
				$info[0]['advise_id'] = $advise_id_user;
			}
			$this->breadcrumb1 = '评价管理';
			$this->breadcrumb2 = '预警评价-对用户';
			$this->breadcrumb3 = '回访记录';
			$this->url2 = U('Comment/Warning') . '&role=user';
			$this->assign('advise', $info);
			$this->display();
		}
	}

	/**
	 * 已处理预警评价
	 * 查看回访记录
	 */
	public function Check(){
		$advise_id = I('get.advise_id');
		$advise_id_user = I('get.advise_id_user','');
		if(empty($advise_id_user)) {
			$info = M('user_advise_visit')->where("advise_id = $advise_id and status = 3 and role = 2")->select();
			if ($info) {
				foreach ($info as $k => $v) {
					$info[$k]['add_time'] = date('Y-m-d H:i:s', $info[$k]['add_time']);
					if ($info[$k]['result'] == '1') {
						$info[$k]['result'] = '继续回访';
					} else {
						$info[$k]['result'] = '处理完毕';
					}
				}
			} else {
				$info[0]['advise_id'] = $advise_id;
			}
			$this->breadcrumb1 = '评价管理';
			$this->breadcrumb2 = '已处理预警评价-对师傅';
			$this->breadcrumb3 = '回访记录';
			$this->url2 = U('Comment/Handled') . '&role=master';
			$this->assign('advise', $info);
			$this->display();

		}else{
			$info = M('user_advise_visit')->where("advise_id = $advise_id_user and status = 3 and role = 1")->select();
			if ($info) {
				foreach ($info as $k => $v) {
					$info[$k]['add_time'] = date('Y-m-d H:i:s', $info[$k]['add_time']);
					if ($info[$k]['result'] == '1') {
						$info[$k]['result'] = '继续回访';
					} else {
						$info[$k]['result'] = '处理完毕';
					}
				}
			} else {
				$info[0]['advise_id'] = $advise_id_user;
			}
			$this->breadcrumb1 = '评价管理';
			$this->breadcrumb2 = '已预警评价-对用户';
			$this->breadcrumb3 = '回访记录';
			$this->url2 = U('Comment/Handled') . '&role=user';
			$this->assign('advise', $info);
			$this->display();
		}
	}

	/**
	 * 增加回访记录
	 */

	public function addReturnVisit(){
		if(IS_POST){
			$role = I('post.advise_id_user');
			if($role==''){
				$data['role'] = '2';
			}else{
				$data['role'] = '1';
			}
			$data['advise_id'] = I('post.advise_id');
			$data['record'] = I('post.record');
			$data['visitor'] = I('post.visitor');
			$data['result'] = I('post.result');
			$data['status'] ='3';
			$data['add_time'] = time();
			$info = M('user_advise_visit')->add($data);
			if($info){
				operatelog('评价管理','1',$info);
				echo 1;
			}else{
				echo 2;
			}
		}
	}


	/**
	 * 评价管理
	 */

	public function Manage(){
		$account = I('get.account');
		$master = I('get.master');

		if($master){
			$maps['info.id_name'] = array('like',"%$master%");
		}
		if($account){
			$maps['wok.phone'] = array('like',"%$account%");
		}
		$count = $data = M()->table('zsf_user_real_info info')
				->field('info.user_id,info.grade,info.id_name,wok.phone as worker_acc')
				->join('LEFT JOIN zsf_user wok on info.user_id = wok.user_id')
				->where($maps)
				->count();
		$Page  = new \Think\Page($count,10);// 实例化
		$show  = $Page->show();// 分页显示输出

		$data = M()->table('zsf_user_real_info info')
				->field('info.user_id,info.grade,info.id_name,info.is_black,info.deadline_black,info.startTime_black,wok.phone as worker_acc')
			    ->join('LEFT JOIN zsf_user wok on info.user_id = wok.user_id')
				->where($maps)->order("grade desc")->limit($Page->firstRow.','.$Page->listRows)
				->select();

		$map['status'] = array('in','8,9,10,11,12,13,14');
		$map['user_comment'] = array('eq',1);
		foreach($data as $k=>$v){
			if($data[$k]['is_black']==1){
				$edit_time = date('Y-m-d',$v['starttime_black']);
				$end_time = date('Y-m-d',strtotime("$v[deadline_black] day","$v[starttime_black]"));
				$data[$k]['date'] = $edit_time.' - '.$end_time;
			}
			$map['worker_user_id'] = array('eq',$data[$k]['user_id']);
			$data[$k]['order_count'] = M('repair_order')->where($map)->count();
			$info = M('comment_master')->field(array('SUM(skill) as skill','SUM(speed) as speed','SUM(charge) as charge','SUM(attitude) as attitude','SUM(health) as health'))->group('worker_user_id')->where($map)->select();
			$data[$k]['star'] = $info[0]['skill']+$info[0]['speed']+$info[0]['attitude']+$info[0]['health']+$info[0]['charge'];
		}

		$this->breadcrumb1 = '评价管理';
		$this->breadcrumb2 = '师傅平均星级管理';
		$this->assign('Manage',$data);
		$this->assign('page',$show);
		$this->display();
	}

	/**
	 * 删除评价
	 */

	public function Del(){
		if(IS_POST){
			$master = I('post.role_master');
			$user = I('post.role_user');
			$comment_id = I('post.Del');
			$comment_id = implode(',',$comment_id);
			$map['order_id'] = array('in',$comment_id);
			if($master){
				$data = M('comment_master')->where($map)->delete();
				if($data){
					operatelog('评价管理','2',$data);
					echo 1;
					exit;
				}else{
					echo 2;
					exit;
				}
			}elseif($user){
				$data = M('comment_user')->where($map)->delete();
				if($data){
					operatelog('评价管理','2',$data);
					echo 1;
					exit;
				}else{
					echo 2;
					exit;
				}
			}
		}

	}

	/**
	 * 加入黑名单
	 * @param user_id
	 * @param days
	 */

	public function JoinBlack(){
		$user_id = I('post.user_id');
		$day = I('post.day');
		$whe['user_id'] = $user_id;
		$map['is_black'] = 1;
		$map['deadline_black'] = $day;
		$map['startTime_black'] = time();
		$data = M('user_real_info')->where($whe)->save($map);
		if($data){
			$maps['master_status'] = 2;
			M('user')->where($whe)->save($maps);
			echo 1;
			exit;
		}else{
			echo 2;
			exit;
		}

	}

}
?>